package com.example.spring_aop.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * Description: JDK 动态代理
 * User: Li_yizYa
 * Date: 2025/7/24
 * Time: 17:31
 */
public class JDKInvocation implements InvocationHandler {

    // 目标对象/被代理对象
    private Object target;

    public JDKInvocation(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // before
        System.out.println("开始代理");
        // 通过反射执行目标对象的目标方法
        Object result = method.invoke(target, args);
        // after
        System.out.println("结束代理");
        return result;
    }
}
